package com.jjyu.controller;

import com.jjyu.entity.Feedback;
import com.jjyu.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/feedback")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    @PostMapping("/recommendations")
    public ResponseEntity<?> submitFeedback(@RequestBody Feedback feedback) {
        try {
            // 在service层已经添加了验证逻辑，这里直接调用save方法
            if (feedbackService.save(feedback)) {
                return ResponseEntity.ok(feedback);
            } else {
                return ResponseEntity.badRequest().body("Failed to save feedback");
            }
        } catch (IllegalArgumentException e) {
            // 捕获service层抛出的异常
            return ResponseEntity.badRequest().body(e.getMessage());
        }
    }

    // 可以添加其他端点，例如获取反馈列表、更新反馈等
}